[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
exit() Terminate Process after Cleanup
#include <process.h> Required for declarations only
#include <stdlib.h> Use either process.h or stdlib.h
void exit(status);
int status; Exit status
exit() terminates the calling process and returns the low-byte of
'status' (status & 0xFF) to the waiting parent process, if one
exists. Before termination, all functions registered with atexit()
are called in a last-in, first-out order, all stream buffers are
flushed, and all files are closed.
Returns: There is no return value; exit() does not return to
the calling process. 'status' is returned to the
parent process. (The parent process is usually the
operating system.)
Notes: exit(0) is automatically called when main() exits.
Typically, the exit status is set to 0 to indicate a
normal exit, and to some other value to indicate an
error. This is not required, however.
_exit() has the same function as exit(), but _exit()
does not flush the stream buffers or execute
functions registered with atexit() before
terminating.
-------------------------------- Example ---------------------------------
The following statements set the exit status to 1 if more than one
command line argument is passed.
#include <stdio.h> /* for 'printf' */
#include <stdlib.h> /* for 'exit' (also in <process.h>) */
main(argc, argv)
int argc;
char *argv[];
{
if (argc > 2) {
perror("no more than 1 command line parameter allowed\n");
exit(1);
}
/* exit here with a status of 0 */
}
See Also:
_exit()
abort()
exec...()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson